﻿using Microsoft.AspNetCore.Mvc;
using Abp.AspNetCore.Mvc.Authorization;
using Partner.Surround.Controllers;
using Partner.Surround.Logging;
using Partner.Surround.Configuration;
using System.Threading.Tasks;
using Partner.Surround.Configuration.Dto;

namespace Partner.Surround.Web.Controllers
{
    /// <summary>
    /// 系统设置控制器
    /// </summary>
    [AbpMvcAuthorize]
    public class HostSettingsController : SurroundControllerBase
    {
        private readonly IConfigurationAppService _configurationAppService;

        public HostSettingsController(IConfigurationAppService configurationAppService)
        {
            _configurationAppService = configurationAppService;
        }

        /// <summary>
        /// 系统设置首页
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> Index()
        {
            var settings = await _configurationAppService.GetAllHostSettings();

            return View(settings);
        }

        /// <summary>
        /// 更新系统设置
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> UpdateAllSettings([FromBody]HostSettingsEditDto input)
        {
            await _configurationAppService.UpdateAllHostSettings(input);
            return Json(new { code = 200, msg = "更新设置成功" });
        }
    }
}
